<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>密码重置</title>
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <link href="../../layui/css/iconfont/iconfont.css" rel="stylesheet" type="text/css">
    <script src="../../layui/css/iconfont/iconfont.js"></script>
    <script src="../../js/util.js"></script>
    <script type="text/javascript">
        var wait = 60;

        function time() {
            if (wait == 0) {
                document.getElementById("send").removeAttribute("disabled");
                document.getElementById("send").value = "重新发送";
                wait = 60;
            } else {
                document.getElementById("send").setAttribute("disabled", true);
                document.getElementById("send").value = "重新发送" + wait + "s";
                wait--;
                setTimeout(function () {
                        time()
                    },
                    1000)
            }
        }

        layui.use(['jquery', 'layer'], function () {
            var $ = layui.$;
            var layer = layui.layer;
            $('#send').on('click', function () {
                var msisdn = $.trim($('#msisdn').val());
                var password = $.trim($('#password').val());
                var password2 = $.trim($('#password2').val());
                if (isNull(msisdn)) {
                    layer.msg("请输入手机号");
                } else if (isNull(password)) {
                    layer.msg("请输入密码");
                } else if (testPassword(password)) {
                    layer.msg("密码不符合规范");
                } else if (isNull(password2)) {
                    layer.msg("请确认密码");
                } else if (password != password2) {
                    layer.msg("密码不一致");
                } else {
                    loading = layer.load(0, {shade: false});
                    //确认账号的有效性
                    var judge = "/reset/judge?msisdn=" + msisdn;
                    $.ajax({
                        type: 'post',
                        url: judge,
                        success: function (json) {

                            if (json.data == '1') {
                                var send = {
                                    flag: 'reset',
                                    msisdn: msisdn
                                };
                                $.ajax({
                                    type: 'post',
                                    url: "/login/sendCode",
                                    data: send
                                    , beforeSend: function () {
                                        layer.close(loading);
                                        time();
                                    },
                                    success: (function (json) {
                                        layer.msg("发送成功")
                                    })
                                });
                            } else {
                                layer.close(loading);
                                layer.msg("账号不存在");
                            }
                        }
                        , error: function () {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    });
                }
            });
            $('#reset').on('click', function () {
                var msisdn = $('#msisdn').val();
                var password = $('#password').val();
                var password2 = $('#password2').val();
                var code = $('#code').val();
                if (isNull(msisdn)) {
                    layer.msg("请输入手机号");
                } else if (isNull(password)) {
                    layer.msg("请输入密码");
                } else if (testPassword(password)) {
                    layer.msg("密码不符合规范");
                } else if (isNull(password2)) {
                    layer.msg("请确认密码");
                } else if (password != password2) {
                    layer.msg("密码不一致");
                } else if (isNull(code)) {
                    layer.msg("请输入验证码");
                }
                else {
                    //校验验证码
                    $.ajax({
                        type: 'post',
                        url: '/login/judgeMentCode?code='+code,
                        success: function (json) {
                            if (json == "success") {
                                var param = {
                                    msisdn: msisdn,
                                    password: password
                                };
                                //重置密码
                                $.ajax({
                                        type: 'post',
                                        data: param,
                                        url: '/reset/reset',
                                        success: function (json) {
                                            if (json.data == 1) {
                                                layer.confirm('密码修改成功，点击确认，返回登录界面？', {
                                                    btn: ['确认'] //按钮
                                                }, function () {
                                                    window.location.href = "login.html";
                                                });
                                            } else {
                                                layer.msg("修改失败，请重试");
                                            }
                                        }
                                        , error:

                                            function () {
                                                layer.msg('系统异常，请联系管理员处理!');
                                            }
                                    }
                                );
                            }
                            else if (json == "fail") {
                                layer.msg("验证码错误");
                            } else if (json == "long") {
                                layer.msg("验证码超时");
                            }
                        }
                        , error:

                            function () {
                                layer.msg('系统异常，请联系管理员处理!');
                            }
                    })
                }
            })
            ;

        })
        ;
    </script>
</head>
<body>
<div class="resetpassword-bg">
    <div class="resetpassword-icon-bg"></div>
    <div class="resetpassword-cloud-bg"></div>
    <div class="resetpassword-form">
        <h4 class="resetpassword-form-title">密码重置</h4>
        <div class="resetpassword-form-content-box">
            <div class="resetpassword-form-item-box">
                <i class="iconfont icon-shouji resetpassword-form-icon"></i>
                <input type="text" placeholder="手机号码" id="msisdn">
            </div>
            <div class="login-form-item-box password-form">
                <i class="iconfont icon-222yonghu_mima_yuechi2 login-form-icon"></i>
                <input type="password" placeholder="新密码" id="password">

            </div>
            <div class="login-form-item-box password-form">
                <i class="iconfont icon-222yonghu_mima_yuechi2 login-form-icon"></i>
                <input type="password" placeholder="确认密码" id="password2">
            </div>
            <div class="login-form-item-inlinebox">
                <div class="login-form-item-box">
                    <i class="iconfont icon-yanzhengma login-form-icon"></i>
                    <input type="text" placeholder="短信验证码" id="code">
                </div>
                <input type="button" class="send-btn" id="send" value="发送验证码">
            </div>
            <p style="color: #0C0C0C;font-size: 3px">提示:新密码数量至少为6位，并且包含英文，数字以及特殊字符3种格式</p>
        </div>
        <a class="login-btn" href="#" id="reset">重置密码</a>
    </div>
</div>
</body>
</html>